package com.wang.todoList.controller;


import com.wang.todoList.VO.PageInfo;
import com.wang.todoList.entity.TodoInfo;
import com.wang.todoList.service.TodoInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zifan
 * @since 2021-07-24
 */
@RestController
@RequestMapping("/todoInfo")
public class TodoInfoController {
    @Autowired
    private TodoInfoService todoInfoService;

    @ApiOperation(value = "获取该用户下所有的todo")
    @PostMapping("/page")
    public Map<String,Object> getTodos(HttpServletRequest request, @RequestBody PageInfo pageInfo){
        return todoInfoService.getTodos(request,pageInfo);
    }

    @ApiOperation(value = "新增一条数据")
    @PostMapping("/")
    public Map<String,Object> addTodos(HttpServletRequest request,@RequestBody TodoInfo todoInfo){
        return todoInfoService.addTodos(request,todoInfo);
    }

    @ApiOperation(value = "修改数据状态")
    @PutMapping("/")
    public Map<String,Object> updateTodosStatus(@RequestBody TodoInfo todoInfo){
        return todoInfoService.updateTodosStatus(todoInfo);
    }

    @ApiOperation(value = "修改todo的内容")
    @PostMapping("/updateContent")
    public Map<String,Object> updateTodoContent(@RequestBody TodoInfo todoInfo){
        return todoInfoService.updateTodoContent(todoInfo);
    }

    @ApiOperation("删除所有已取消")
    @GetMapping("/deleteAllCancel")
    public Map<String, Object> deleteAllCancel(HttpServletRequest request) {
        return todoInfoService.deleteAllCancel(request);
    }

}

